
function rJoiningGame(d){
	var opp = $("#oppInfo");
	$("#oppInfo p").not("#tkJoinGame").remove();
	$("#oppInfo input").prop("disable",true);
	$("#oppInfo button").replaceWith(' <span class="glyphicon glyphicon-check"></span>');
	$("#oppInfo img").replaceWith(' <span class="glyphicon glyphicon-check"></span>');
	opp.prepend("<p>Nombre defaite : "+d["dCounter"]+"</p>");
	opp.prepend("<p>Niveau : "+ d["level"]+"</p>");
	opp.prepend("<p>Nom : "+d["name"]+"</p>");
}

function joiningGame(){
	//alert("Joining : "+$("#tkJoinGame input").val());
	var tk = $("#tkJoinGame input");
	if( tk.val().length > 0 ){
		$("#oppInfo input").prop('disabled', true);
		$("#oppInfo button").prop("disable",true);
		$("#tkJoinGame button").replaceWith(' <img src="../images/valide-joining.gif"/>');
		$.get("/game", {"ACTION":Cst.JOIN_GAME, "USER_ID":user.userId, "GAME_TOKEN":tk.val()})
			.done(function(){
				gameToken = tk.val();
			})
			.fail(function(){
				alert("JOIN_GAME : Echec!!!");
			});	
	}
}
function joinGame(){
	$("#tkJoinGame").html('<input type="text" maxlength="30" placeholder="Enter token" /> <button class="btn btn-default" title="Valider" onClick="joiningGame();" ><span class="glyphicon glyphicon-ok-circle"></span></button>');
}

function receiveGameToken(d){
	gameToken = d;
	$("#tk"+user.userId).html("Token : "+d);
}

function getGameToken(){
	$.get("/onlineCheckers", {"ACTION":Cst.NEW_GAME_TOKEN, "USER_ID":user.userId})
	.fail(function(){
		alert("NEW_GAME_TOKEN : Echec!!!");
	});	
	$("#tk"+user.userId).html(' <img src="../images/token-load.gif"/>');
}
